﻿using System;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Hxsoft.AppV1;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.SystemInit
{
	public partial class Default : BasePage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (RightValidate())
			{
				if (!IsPostBack)
					this.DataBind();
			}
		}

		protected void BtnInitPermissions_ServerClick(object sender, EventArgs e)
		{
			if (RightValidate())
			{
				Hxsoft.AppV1.Module.SystemInit.Instance.InitPermissions();
			}
		}

		protected void BtnInitRoles_ServerClick(object sender, EventArgs e)
		{
			if (RightValidate())
			{
				Hxsoft.AppV1.Module.SystemInit.InitRoles();
			}
		}

		protected void BtnInitUsers_ServerClick(object sender, EventArgs e)
		{
			if (RightValidate())
				Hxsoft.AppV1.Module.SystemInit.InitUsers();
		}

		protected void BtnSynchroModulePermissionRegister_ServerClick(object sender, EventArgs e)
		{
			if (RightValidate())
				Modules.SyncArticleReleasePermissionRegister();
		}

		protected void BtnSynchroPageBlockPermissionRegister_ServerClick(object sender, EventArgs e)
		{
			if (RightValidate())
				PageBlocks.SyncBlockEditPermissionRegister();
		}

		protected void BtnSynchroLinkClassPermissionRegister_ServerClick(object sender, EventArgs e)
		{
			if (RightValidate())
				LinkClasses.SyncLinkReleasePermissionRegister();
		}

		protected void BtnSynchroVoteTypePermissionRegister_ServerClick(object sender, EventArgs e)
		{
			if (RightValidate())
				VoteClasses.SyncVoteReleasePermissionRegister();
		}

		/// <summary>
		/// 返回权限验证结果，如果验证失败则显示消息提示。
		/// </summary>
		/// <returns>布尔值代表权限验证是否通过。</returns>
		public bool RightValidate()
		{
			bool right = Hxsoft.AppV1.Module.SystemInit.GetInitRight();
			if (!right)
			{
				Messages.Add(new PageMessage(false, null, PageMessageType.Error, Res.PermissionExceptionMessageTitle, Res.PermissionExceptionMessage));
			}
			return right;
		}
	}
}
